package com.bt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bt.mapper.DtsTopicMapper;
import com.bt.pojo.DtsTopic;
import com.bt.service.DtsTopicService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author wbt
 * @version v1.0
 * @project shop_manage
 * @data 2022/9/26 14:23
 **/
@Service
public class DtsTopicServiceImpl implements DtsTopicService {
    @Autowired
    private DtsTopicMapper dtsTopicMapper;
    @Override
    public IPage<DtsTopic> findDtsTopicByPage(Integer page, Integer limit, String title, String subtitle, String sort, String order) {
        return dtsTopicMapper.selectPage(new Page<DtsTopic>(page,limit),new QueryWrapper<DtsTopic>().like(!StringUtils.isEmpty(title),"title",title).like(!StringUtils.isEmpty(subtitle),"subtitle",subtitle).orderBy(!StringUtils.isEmpty(order),"desc".equals(order),sort));
    }

    @Override
    public void insertDtsTopic(DtsTopic dtsTopic) {
        dtsTopic.setAddTime(new Date());
        dtsTopic.setUpdateTime(new Date());
        dtsTopicMapper.insert(dtsTopic);
    }

    @Override
    public void updateDtsTopic(DtsTopic dtsTopic) {
        dtsTopic.setUpdateTime(new Date());
        dtsTopicMapper.updateById(dtsTopic);
    }

    @Override
    public void deleteDtsTopic(DtsTopic dtsTopic) {
        dtsTopicMapper.deleteById(dtsTopic.getId());
    }
}
